package com.zrf.gulimall.product.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author zhanrf
 * @Date 2021/12/27 21:27
 */
@EnableConfigurationProperties(value = ThreadProperties.class)
@Configuration
public class ThreadPoolConfig {
	@Bean
	public ThreadPoolExecutor threadPoolExecutor(ThreadProperties threadProperties) {
		return new ThreadPoolExecutor(threadProperties.getCorePoolSize(), threadProperties.getMaximumPoolSize(),
				threadProperties.getKeepAliveTime(), TimeUnit.SECONDS,
				new LinkedBlockingDeque<>(10000), Executors.defaultThreadFactory(),
				new ThreadPoolExecutor.AbortPolicy());
	}
}
